<?php
// +----------------------------------------------------------------------
// | Demo [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.lmx0536.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: limx <715557344@qq.com> <http://www.lmx0536.cn>
// +----------------------------------------------------------------------
// | Date: 2017/2/1 Time: 下午10:14
// +----------------------------------------------------------------------

namespace MyApp\Traits;

use limx\phalcon\Cli\Color;

trait Email
{
    static function sendEmail($msg)
    {

        $mail = new \PHPMailer;

        $mail->SMTPDebug = 3;                               // Enable verbose debug output

        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.qq.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = env('SEND_EMAIL');                 // SMTP username
        $mail->Password = env('SEND_PASSWORD');                           // SMTP password
        $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 465;                                    // TCP port to connect to

        $mail->setFrom(env('SEND_EMAIL'), '李铭昕');
        $mail->addAddress('715557344@qq.com', 'Joe User');     // Add a recipient

        $mail->isHTML(true);                                  // Set email format to HTML

        $mail->Subject = '违章查询';
        $mail->Body = '鲁G' . env('HPHM') . '的车主，您好。<br/><b>' . $msg . '</b>';

        if (!$mail->send()) {
            echo Color::error('Message could not be sent.');
            echo Color::error('Mailer Error: ' . $mail->ErrorInfo);
        } else {
            echo Color::success('Message has been sent');
        }
    }

}